package cn.lijida.weiwei.favor.commons.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import cn.lijida.weiwei.favor.commons.constant.Conf;
import cn.lijida.weiwei.favor.commons.filter.LoginIdFilter;

@Configuration
@DependsOn(value = "springContextUtils")
public class FilterConfig{
	
	@Value("${favor.safe.excluded-path:/sys/login/member}")
	private String excludedPath;
	
	@Value("${favor.safe.logout-path:/sys/login/logout}")
	private String logoutPath;

	@Bean
    public FilterRegistrationBean<LoginIdFilter> loginIdFilterRegistration() {

        // xxl-sso, filter init
        FilterRegistrationBean<LoginIdFilter> registration = new FilterRegistrationBean<LoginIdFilter>();

        registration.setName("LoginIdWebFilter");
        registration.setOrder(1);
        registration.addUrlPatterns("/*");
        registration.setFilter(new LoginIdFilter());
        registration.addInitParameter(Conf.LOGOUT_PATH, logoutPath);
        registration.addInitParameter(Conf.EXCLUDED_PATHS, excludedPath);

        return registration;
    }
}
